package org.example.Polls;

public class PollHelper {
	
	public static Poll getPoll(Long pollId, boolean refresh) throws Exception {
		Poll poll = PollCache.get(pollId);
		if (refresh || poll == null) {
			RequestContext ctxt = RequestContext.getContext();
			if (ctxt == null)
				throw new IllegalStateException("RequestContext is null");
    		PollService pollService = DefaultServiceFactory.getInstance().createPollService();
    		poll = pollService.getPoll(ctxt, pollId, true, true);
    		PollCache.add(poll);
		}
		return poll;
	}
	
	public static Poll getPoll(Long pollId) throws Exception {
		return getPoll(pollId, false);
	}

}
